# coding: utf-8
'''
author: Aeenf
title: 获取优衣库官网上门店的分布和名称
'''

import requests
import pandas as pd
from bs4 import BeautifulSoup
import time
import lxml

class Uniqlo(object):
    def __init__(self):
        self.url = r'http://www.uniqlo.com/cn/shop/'
        self.headers = {
            'User-Agent': 'Mozilla/5.0(Windows NT 6.2 Win64 64) AppleWebKit/537.36(KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'
        }

    def get_url(self):
        response_url = requests.get(self.url, headers=self.headers)
        response_url.encoding = 'utf-8'
        soup_url = BeautifulSoup(response_url.text, 'lxml')
        return soup_url.select('#boxCompanyEntry a')
        #soup_url.select('a[href]')

    def deal_with_url(self, lst):
        '''对下载的数据进行处理'''
        # for i in lst:
        #     print(i)
        df = pd.Series(lst)
        df.to_csv('I:\\地址信息.csv', encoding='utf-8')
        return 'ok'

if __name__ == '__main__':
    uniqlo = Uniqlo()
    lst = uniqlo.get_url()
    print(uniqlo.deal_with_url(lst))
